<template>
  <div>
    <myheader />
    分类<reply :data='catelist'/>
    <van-field
      v-model="form.name"
      name="name"
      label="名称"
      placeholder="名称"
      :rules="[{ required: true, message: '请填写名称' }]"
    />
    <van-field
      v-model="form.types"
      name="types"
      label="等级"
      placeholder="等级"
      :rules="[{ required: true, message: '请填写等级' }]"
    />
    <van-field
      v-model="form.params"
      name="params"
      label="参数配置"
      placeholder="参数配置"
    />
    <van-button
      round
      block
      type="info"
      name="button1"
      native-type="submit"
      @click="add"
      id="button1"
      >登录</van-button
    >
  </div>
</template>

<script>
import myheader from "./myheader.vue"
import reply from './reply.vue'
;
export default {
  data() {
    return {
      form: { parent: 0 },
      catelist:{}
    };
  },
  methods: {
    add() {
      let pid = localStorage.getItem('pid')
      if (pid){
        this.form.parent = pid

      }
      this.$axios.post("/course/add_cate", this.form).then((res) => {
        if (res.data.code == 200) {
          alert("添加成功")
          this.form = {}
        }
      });
    },get_cate(){
      this.$axios.get('/course/add_cate')
      .then(res=>{
        if(res.data.code==200){
         this.catelist={'id':0,'name':'','son':res.data.list}
          
        }
      })
    }

  },
  mounted() {
    this.get_cate()
    localStorage.setItem('pid','')
  },
  components: {
    'myheader': myheader,
    'reply':reply

  },
};
</script>

<style scoped>
</style>